package org.bmp.zemail.home.controllers;

import java.security.Principal;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {
	
	public final static String APP_ROOT_MAPPING = "/";
	public final static String ROOT_MAPPING = "/home";
	public final static String DEFAULT_VIEW = "/home/home";
	
	@RequestMapping(value= { HomeController.ROOT_MAPPING, HomeController.APP_ROOT_MAPPING })
	public String initPage(HttpServletRequest request, ModelMap modelMap) {
		System.out.println("HomeController.initPage");//TODO BM replace with logger
		
		//get username
		Principal user = request.getUserPrincipal();
		String userName = user.getName();
		modelMap.addAttribute("userName", userName);
		
		//return view
		return DEFAULT_VIEW;
	}
	
}
